package com.nuoniu.sibanyun.mapper.so;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nuoniu.sibanyun.entity.so.VSaleOrderMain;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 销售订单主表 Mapper 接口
 * </p>
 *
 * @author baiqiang
 * @since 2020-11-26
 */
@Mapper
@Component
public interface VSaleOrderMainMapper extends BaseMapper<VSaleOrderMain> {

    @Select("select voucher_code from scs_order where company_id=#{companyId} and date_format(now(), #{dateStr})=date_format(create_date, #{dateStr}) AND data_source = #{dataSource} order by create_date desc limit 1")
    String getCode(Integer companyId,  String dateStr, String dataSource);

    @Select("select * from scs_order")
    List<VSaleOrderMain> getBySaleType(Long id);

    @Select("select * from scs_order where source_voucher_id = #{sourceId}")
    List<VSaleOrderMain> getBySourceId(Long sourceId);

    @Update("UPDATE scs_order SET is_generate_work_plan = #{status} WHERE id = #{saleOrderId}")
    boolean updateGenerateWorkPlanStatus(Long saleOrderId, Integer status);
}
